package com.think.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * Created by Administrator on 2018/5/23 0023.
 */
public class HttpServletRequestUtil {
    private static final Logger logger = LoggerFactory.getLogger(HttpServletRequestUtil.class);
    /**
    * @description:
     * @param request
    * @date: 上午 11:12 2018/5/23 0023
    */
    public static String readAsChars(HttpServletRequest request) {
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder("");
        try {
            br = request.getReader();
            String str;
            while ((str = br.readLine()) != null) {
                sb.append(str);
            }
            br.close();
        } catch (IOException e) {
            logger.info("读取异常：" + e.getMessage());
            e.printStackTrace();
        }
        finally {
            if (null != br) {
                try {
                    br.close();
                } catch (IOException e) {
                    logger.info("IO关闭异常：" + e.getMessage());
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }
}
